import 'dart:async';
import 'package:animated_interpolation/smart_tabbar.dart';
import 'package:animated_interpolation/sweet_indicator_painter.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:find_friend/common/alert_tool.dart';
import 'package:find_friend/common/common_widget.dart';
import 'package:find_friend/common/play_audio_flr.dart';
import 'package:find_friend/const/const.dart';
import 'package:find_friend/network/network.dart';
import 'package:find_friend/pages/im/pages/conversation_page.dart';
import 'package:find_friend/pages/login&register/model/shared_user_info.dart';
import 'package:find_friend/pages/mine/mine_setting/setting_notifier.dart';
import 'package:find_friend/pages/mine/view/mine_tag_widget.dart';
import 'package:find_friend/pages/xspace/model/school_model.dart' show Voice;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'mine_photos_wall.dart';
import 'mine_xspace.dart';
import 'model/messagemodel.dart' as message;
import 'view/mine_sex_widget.dart';

class MinePreviewPage extends StatefulWidget {

  final String mobile;
  final bool isneedpop; // 点击私信返回聊天
  final Function(String remarkName) onModRemarkName; // 修改备注回调

  const MinePreviewPage({Key key, this.mobile, this.isneedpop = false, this.onModRemarkName}) : super(key: key);

  @override
  _MinePreviewPageState createState() => _MinePreviewPageState();
}

class _MinePreviewPageState extends State<MinePreviewPage> with SingleTickerProviderStateMixin {

  final focusNode = FocusNode();
  int danmu = 0; // 默认为弹幕区
  TabController _tabController;
  SharedUserInfo _userInfo = SharedUserInfo();
  Voice signvoice;
  bool isself = false;
  Timer _timer; // 弹幕计时器
  List<message.MineMessageModel> danmuList = [];
  List<MinePreviewDanmu> danmuWidgetList = [];
  TextEditingController _textEditingController = TextEditingController();
  PageController _pageController;
  int currTabIndex = 0;
  static const String KeyUserDanmuSwitch = "KeyUserDanmuSwitch";
  bool isDanmuOpen = false; // 弹幕开关
  bool isfollow = false;
  @override
  initState() {
    super.initState();

    _tabController = TabController(length: 2, vsync: this);
    _pageController = PageController(initialPage: 0);
    _tabController.addListener(() { 
      print(_tabController.index);
      setState(() {
        danmu = _tabController.index;
        setState(() {
          currTabIndex = _tabController.index;
        });
        if(danmuWidgetList.length > 1) danmuWidgetList.removeRange(1, danmuWidgetList.length - 1);
      });
    });

    // build 完成之后再请求接口
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) { 
      _requestData();
    });
    _checkIsSelf(); // 是否是自己
    _requestDanmu();// 查询弹幕留言
  }

  _checkIsSelf() {
    SharedUserInfo.instance().then((value){
      setState(() {
        isself = value.mobile == widget.mobile;
      });
    });
  }

  @override
  dispose(){
    _tabController.dispose();
    _textEditingController.dispose();
    _pageController.dispose();
    danmuWidgetList.clear();
    _timer?.cancel();
    _timer = null;
    super.dispose();
  }

  _requestLike() {
    AlertTool.showLoadingDialog(context);
    Networktool.request(API.follow, params: {isfollow == true ? "mobiles" : "mobile": widget.mobile}, method: isfollow == true ? NETWORKHTTPMethod.DELETE : NETWORKHTTPMethod.POST, success: (data){
      setState(() {
        // _userInfo.follow = !_userInfo.follow;
        isfollow = !isfollow;
      });
    },
    fail: (msg) => AlertTool.showToast(msg),
    finaly: () => Navigator.of(context).pop());
  }

  _requestData() {
    Networktool.request(API.center, params: {"mobile": widget.mobile}, method: NETWORKHTTPMethod.GET, success: (data){
      if(data != null) {
        SharedUserInfo userInfo = SharedUserInfo.fromJson(data["data"]);
        _userInfo = userInfo;
        isfollow = userInfo.followflag != null;
        if(mounted){
          setState(() {
            
          });
        }
      }
    },
    fail: (msg) => AlertTool.showToast(msg),
    
    );
  }

  _requestFeedback(String sender) {
    Networktool.request(API.message, params: {"mobile": widget.mobile, "message":sender}, success: (data){
      if(data != null) {
        AlertTool.showToast("留言成功");
        SharedUserInfo.instance().then((value){
          danmuList.add(message.MineMessageModel(avatar: value.avatar,message: sender));
        });
      }
    },
    fail: (msg) => AlertTool.showToast(msg));
  }

  _requestDanmu() {
    Networktool.request(API.messageme, params: {"tomobile": widget.mobile}, method: NETWORKHTTPMethod.GET, success: (data){
      if(data != null) {
        message.Autogenerated d = message.Autogenerated.fromJson(data);
        danmuList = d.data;
        SharedPreferences.getInstance().then((value) {
          var begin = value.getBool(KeyUserDanmuSwitch + widget.mobile);
          if(begin == null) return;
          setState(() {
            isDanmuOpen = begin;
          });
          _onMineTapOpen(begin);
        });
      }
    },
    fail: (msg) => AlertTool.showToast(msg));
  }

  void _onMineTapOpen(bool open) {
    open ? _beginDanmu() : _stopDanmu();
  }

  _beginDanmu() {
    if(danmuList.isEmpty) return;
    double offset = 0;
    int index = 0;
    List<String> alreadyMobile = []; // 一个弹幕
    _timer = Timer.periodic(Duration(milliseconds: 500), (t){
      if(danmuWidgetList.length > 10){
        return;
      }
      if(index >= danmuList.length - 1 ){
        index = 0;
      } else {
        index += 1;
      }
      // Future.delayed(Duration(seconds: 5)).then((value) => );
      
      message.MineMessageModel model = danmuList[index];
      if(!alreadyMobile.contains(model.mobile)){
        alreadyMobile.add(model.mobile);
        danmuWidgetList.add(
          MinePreviewDanmu(
            key: ValueKey(DateTime.now().millisecondsSinceEpoch),
            offsetTop: offset,
            model: model,
            onAnimationFinish: (sender, mobile){
              danmuWidgetList.removeWhere((element) => element.key == sender);
              alreadyMobile.remove(mobile);
            },
          )
        );
        offset += 40 ;
        if(offset > 200) offset = 0;
        
        setState(() {
          
        });
      }
    });  
  }

  _stopDanmu() {
    _timer?.cancel();
    _timer = null;
    setState(() {
      danmuWidgetList.clear();
    });
  }


  // 拉入黑名单
  _addBlackList() {
    Networktool.request(API.friendgroupset, params: {"mobile": widget.mobile, "gid": -1}, success: (data){
      AlertTool.showToast("操作成功");
    }
    ,fail: (msg) => AlertTool.showToast(msg));
  }

  _addRemarkRequest({String remark, int top}) {
    Map<String, dynamic> params = {"mobile": widget.mobile};
    if(remark != null) {
      params["remark"] = remark;
    }
    if(top != null) {
      params['top'] = top;
    }
    Networktool.request(API.follow, params: params, method: NETWORKHTTPMethod.PUT, success: (data){
      if(remark != null) {
        setState(() {
          _userInfo.followRemark = remark == "" ? null : remark;
        });
        if(widget.onModRemarkName != null) widget.onModRemarkName(_userInfo.remarkname);
        _textEditingController.clear();
      } else {
        AlertTool.showToast("设置成功");
      }
    }
    ,fail: (msg) => AlertTool.showToast(msg));
  }

  Widget _customBar(BuildContext context, double top) {
      return Container(
        padding: EdgeInsets.only(top: top),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            IconButton(
              onPressed: (){
                Navigator.of(context).pop();
              },
              icon: Image.asset("assets/fanhui.png", color: Colors.white,),
            ),
            Offstage(
              offstage: isself,
              child: IconButton(
                onPressed: (){
                  AlertTool.showBottomDialog(context, ["备注","关注置顶","拉入黑名单","举报"], onTapIndex: (index){
                    Navigator.pop(context);
                    switch (index) {
                      case 0:{
                        if(!isfollow) {
                          AlertTool.showToast("请先关注!");
                          return;
                        }
                        if(_userInfo.followRemark != null) _textEditingController.text = _userInfo.followRemark;
                        Future.delayed(Duration(milliseconds: 100)).then((value){
                          AlertTool.showInputDialog(context, _textEditingController, title: "备注\n输入备注名称", placeholder: "请输入备注名称", sureCallback: (str){
                            _addRemarkRequest(remark: str);
                          });
                        });
                      }
                        break;
                      case 1:
                        if(!isfollow) {
                          AlertTool.showToast("请先关注!");
                          return;
                        }
                        _addRemarkRequest(top: 1);
                        break;
                      case 2:
                        _addBlackList();
                        break;
                      case 3:
                        Navigator.of(context).pushNamed("/msgreport",arguments: widget.mobile);
                        break;
                      default:
                    }
                  });
                },
                icon: Icon(Icons.more_horiz, color: Colors.white,),
              ),
            )
          ],
        ),
      );
    }

  

  String _getname() {
    var res = "";
    if(_userInfo.followRemark != null) res = res + "(${_userInfo.nickname})";
    return res;
  }

  Widget _remarkNameWidget() {
    return Text.rich(TextSpan(
      children: [
        TextSpan(text: _userInfo.followRemark ?? _userInfo.nickname, style: instanceTextStyle(18, Colors.white, fontWeight: FontWeight.w500)),
        TextSpan(text: _getname(), style: instanceTextStyle(15, Colors.white)),
      ]
    ));
  }

  Widget _userHead(BuildContext context, Size size) {
      return Container(
          padding: const EdgeInsets.only(left: 10,),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Padding(
                padding: const EdgeInsets.only(top: 8.0),
                child: PhysicalModel(
                  color: Colors.transparent,
                  shape: BoxShape.circle,
                  clipBehavior: Clip.antiAlias,
                  shadowColor: Colors.black,
                  elevation: 2,
                  child: Image.network(
                        _userInfo.avatar ?? "",
                        height: 75.w,
                        width: 75.w,
                        fit: BoxFit.cover,
                      ),
                ),
              ),
              Expanded(
                child: Container(
                  padding: const EdgeInsets.only(left: 10),
                  child: Column(
                    mainAxisSize: MainAxisSize.max,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        width: size.width * 0.5,
                        child: _remarkNameWidget()),
                      SizedBox(height: 5,),
                      MineSexWidget(userInfo: _userInfo,),
                      SizedBox(height: 5,),
                      MineTagWidget(label: _userInfo.label,),
                      SizedBox(height: 5,),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Expanded(
                            child: Text(
                              "${_userInfo.bio ?? "这人啥都没有留下~"}",
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: instanceTextStyle(11, Colors.white)
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.only(right: 10.0),
                            child: AudioFlrWidget(signvoice: _userInfo.signvoice,),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        );
    }

  Widget _followWidget() {
      return Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              InkWell(
                onTap: _requestLike,
                child: Container(
                  width: MediaQuery.of(context).size.width * 0.32,
                  alignment: Alignment.center,
                  padding: const EdgeInsets.symmetric(vertical: 10),
                  decoration: BoxDecoration(
                    color: Colors.white54,
                    boxShadow: [
                      BoxShadow(blurRadius: 10, color: Colors.black12)
                    ],
                    borderRadius: BorderRadius.circular(30)
                  ),
                  child: Text(isfollow ? "已关注" : "关注", style: instanceTextStyle(15, APP_main_color),),
                ),
              ),
              InkWell(
                onTap: (){
                  if(widget.isneedpop){
                    Navigator.of(context).pop();
                  } else {
                    if(_userInfo.mobile == null) {
                      AlertTool.showToast("未获取到用户数据");
                      return;
                    }
                    Map arg = {"coversationType":1,"targetId":_userInfo.mobile, "nickname":_userInfo.followRemark};
                    push(context, ConversationPage(arguments: arg,));
                  }
                },
                child: Container(
                  width: MediaQuery.of(context).size.width * 0.32,
                  alignment: Alignment.center,
                  padding: const EdgeInsets.symmetric(vertical: 10),
                  decoration: BoxDecoration(
                    color: Colors.white54,
                    boxShadow: [
                      BoxShadow(blurRadius: 10, color: Colors.black12)
                    ],
                    borderRadius: BorderRadius.circular(30)
                  ),
                  child: Text("私信", style: instanceTextStyle(15, APP_font_black),),
                ),
              ),
            ],
          );
    }

  @override
  Widget build(BuildContext context) {

    final size = MediaQuery.of(context).size;
    final padding = MediaQuery.of(context).padding;
    double keybordheight = MediaQuery.of(context).viewInsets.bottom;
    return SafeArea(
      top: false,
      bottom: false,
      child: Scaffold(
        resizeToAvoidBottomPadding: false,
        body: GestureDetector(
          behavior: HitTestBehavior.translucent,
          onTap: (){
            focusNode.unfocus();
          },
          child: Stack(
            children: [
              // FadeInImage.memoryNetwork(
              //   placeholder: kTransparentImage,
              //   image: _userInfo.longback ?? "",
              //   width: size.width, height: size.height, fit: BoxFit.cover,
              // ),
              CachedNetworkImage(
                placeholder: (context, url) => Container(color: Colors.black12,),
                imageUrl: _userInfo.longback ?? "",
                width: size.width,
                height: size.height,
                fit: BoxFit.cover,
              ),
              Positioned(
                top: 0,
                bottom: 0,
                left: 0,
                right: 0,
                child: Container(
                  height: size.height,
                  child: Column(
                    children: [
                      _customBar(context, padding.top),
                      _userHead(context, size),
                      Expanded(
                        child: Container(
                          width: size.width,
                          margin: EdgeInsets.only(top: 25),
                          color: Colors.white60,
                          child: Column(
                            children: [
                              Offstage(
                                offstage: _userInfo.photowall == null,
                                child: _PhotoWallWidget(list: _userInfo.photowall ?? [],)
                              ),
                              Container(
                                height: 30.h,
                                padding: const EdgeInsets.symmetric(horizontal: 20),
                                child: SmartTabBar(
                                  labelColor: APP_main_color,
                                  controller: _tabController,
                                  indicatorColor: APP_main_color,
                                  indicatorBuilder: (context,controller,indicator,indicatorSize,tabKeys,old)=>SweetIndicatorPainter(
                                    controller: controller,
                                    indicatorSize: indicatorSize,
                                    indicator: indicator,
                                    tabKeys: tabKeys,
                                    old: old
                                  ),
                                  tabs: [
                                    Text("弹幕区", style: currTabIndex == 0 ? instanceTextStyle(17, APP_font_black,fontWeight: FontWeight.w500) : instanceTextStyle(15, const Color(0xff666666))),
                                    Text("${isself ? '我' : '他'}的X区", style: currTabIndex == 1 ? instanceTextStyle(17, APP_font_black,fontWeight: FontWeight.w500) : instanceTextStyle(15, const Color(0xff666666))),
                                  ],
                                  onTap: (index){
                                    setState(() {
                                      currTabIndex = index;
                                    });
                                    _pageController.jumpToPage(index,);
                                  },
                                ),
                              ),
                              Expanded(
                                child: PageView(
                                  controller: _pageController,
                                  onPageChanged: (index){
                                    setState(() {
                                      currTabIndex = index;
                                    });
                                    _tabController.animateTo(index);
                                  },
                                  children: [
                                    Column(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      children: [
                                        _MineFeedBack(
                                          isopen: isDanmuOpen,
                                          onTapComment: (){
                                            focusNode.requestFocus();
                                          },
                                          onTapOpen: (val){
                                            setState(() {
                                              isDanmuOpen = !isDanmuOpen;
                                            });
                                            SharedPreferences.getInstance().then((value) => value.setBool(KeyUserDanmuSwitch + widget.mobile, isDanmuOpen));
                                            _onMineTapOpen(isDanmuOpen);
                                          },
                                        ),
                                        Expanded(
                                          child: Stack(
                                            children: danmuWidgetList,
                                          ),
                                        ),
                                      ],
                                    ),
                                    MineXSpaceView(showPostButton: false, mobile: _userInfo.mobile,)
                                ]),
                              ),
                            ],
                          ),
                        ),
                      )
                    ],
                  ),
                ),
              ),
              Positioned(
                right: 15,
                bottom: 55 + padding.bottom,
                child: Offstage(
                  offstage: currTabIndex != 0,
                  child: IgnorePointer(
                    ignoring: true,
                    child: Image.asset("assets/nvnpc.png", height: size.height * 0.4, fit: BoxFit.scaleDown,)
                  )
                )
              ),
              Positioned(
                bottom: padding.bottom + 16,
                left: 0,
                right: 0,
                child: Offstage(
                  offstage: danmu != 0,
                  child: _followWidget()
                ),
              ),
              Positioned(
                  left: 0,
                  right: 0,
                  bottom: keybordheight,
                  child: _SendComment(focusNode: focusNode,onFinish: _requestFeedback,),
                ),
            ],
          ),
        ),
      ),
    );
  }
}


///照片墙
class _PhotoWallWidget extends StatelessWidget {

  final List<FileModel> list;
  final String heroPerfix; // 防止hero动画乱窜

  const _PhotoWallWidget({Key key, this.list, this.heroPerfix = "perfix"}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
          height: 90.h,
          margin: const EdgeInsets.symmetric(horizontal: 10),
          child: ListView.builder(
            itemCount: list.length,
            itemExtent: 90.h - 10,
            padding: const EdgeInsets.only(top: 9.5, bottom: 10),
            scrollDirection: Axis.horizontal,
            itemBuilder: (context, index){
              final tagStr = "avatar" + index.toString();
              return GestureDetector(
                          onTap: () async {
                            Navigator.push(context, PageRouteBuilder(
                                pageBuilder: (BuildContext context, Animation animation,
                                    Animation secondaryAnimation) {
                                  return new FadeTransition(
                                    opacity: animation,
                                    child: MinePhotoWallPage(heroTag: heroPerfix + tagStr, list: list,),
                                  );
                                })
                            );
                          },
                          child: Container(
                            padding: const EdgeInsets.only(right: 5),
                            child: Card(
                              margin: const EdgeInsets.all(0),
                              semanticContainer: true,
                              clipBehavior: Clip.antiAlias,
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(8.0),
                              ),
                              elevation: 3,
                              child: Hero(
                                tag: heroPerfix + tagStr,
                                child: CachedNetworkImage(
                                    imageUrl: list[index].url ?? "",
                                    fit: BoxFit.cover,
                                  ),
                              ),
                            ),
                          ),
                        );
          }),
        );
  }
}


///弹幕
class _MineFeedBack extends StatelessWidget {

  final Function() onTapComment;
  final Function(bool open) onTapOpen;
  final bool isopen;

  const _MineFeedBack({Key key , this.isopen = false, this.onTapComment, this.onTapOpen}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    
    final size = MediaQuery.of(context).size;

    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            height: 20,
            width: 45,
            margin: const EdgeInsets.only(top: 25, left: 25),
            child: CustomSwitchButton(
              activeColor: APP_main_color,
              value: isopen,
              thumbHeight: 20,
              onChanged: onTapOpen,
            ),
          ),
          GestureDetector(
            onTap: onTapComment,
            child: Container(
              padding: const EdgeInsets.only(left: 25.0, top: 7.5),
              child: Row(
                children: [
                  Text("发表你的评价吧...", style: instanceTextStyle(11, APP_font_grey),),
                  Image.asset("assets/bianji.png", height: 10, width: 10, color: APP_font_grey,)
                ],
              ),
            ),
          ),
          SizedBox(
            width: size.width  * 0.45,
            child: Divider(color: APP_divider_color,indent: 25,)
          ),
        ],
      ),
    );
  }
}

// 留言
class _SendComment extends StatefulWidget {
  
  final FocusNode focusNode;
  final Function(String val) onFinish;

  const _SendComment({Key key, this.focusNode, this.onFinish}) : super(key: key);

  @override
  __SendCommentState createState() => __SendCommentState();
}

class __SendCommentState extends State<_SendComment> {

  
  final _controller = TextEditingController();
  
  bool offstage = true;

  @override
  void initState() {
    widget.focusNode.addListener(() { 
      setState(() {
        offstage = !widget.focusNode.hasFocus;
      });
    });
    super.initState();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return Offstage(
      offstage: offstage,
      child: Container(
        color: Colors.white,
        padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
        child: Row(
          children: [
            Expanded(
              child: Container(
                    height: 35,
                    child: TextField(
                      autocorrect: false,
                      focusNode: widget.focusNode,
                      controller: _controller,
                      onSubmitted: (val){
                        _controller.clear();
                        widget.focusNode.unfocus();
                      },
                      decoration: InputDecoration(
                        hintStyle: instanceTextStyle(11, APP_font_grey),
                        hintText: "发表你的评价叭...",
                        counterText: "",
                        filled: true,
                        fillColor: APP_scaffold_back_color,
                        contentPadding: const EdgeInsets.only(left: 11.5),
                        focusedBorder: OutlineInputBorder(
                          borderRadius: const BorderRadius.all(const Radius.circular(20)),
                          borderSide: const BorderSide(width: .5, color: APP_divider_color),
                        ),
                        enabledBorder: OutlineInputBorder(
                          borderRadius: const BorderRadius.all(Radius.circular(20)),
                          borderSide: const BorderSide(width: .5, color: APP_divider_color),
                        ),
                        border: OutlineInputBorder(
                          borderRadius: const BorderRadius.all(Radius.circular(20)),
                          borderSide: const BorderSide(width: .5, color: APP_divider_color),
                        ),
                      ),
                      onEditingComplete: (){
                        _controller.clear();
                        widget.focusNode.unfocus();
                      },
                    ),
                  ),
            ),
            InkWell(
              onTap: () {
                if(_controller.text == "") return;
                if(widget.onFinish != null) {
                  widget.onFinish(_controller.text);
                  _controller.clear();
                  widget.focusNode.unfocus();
                }
              },
              child: Container(
                padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
                margin: const EdgeInsets.only(left: 10),
                decoration: BoxDecoration(
                  color: APP_main_color,
                  borderRadius: BorderRadius.circular(20)
                ),
                child: Text("发送", style: instanceTextStyle(14, Colors.white),)
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class MinePreviewDanmu extends StatefulWidget {

  final double offsetTop;
  final Function(Key removeKey, String mobile) onAnimationFinish;
  final message.MineMessageModel model;

  const MinePreviewDanmu({Key key, this.offsetTop, this.onAnimationFinish, this.model}) : super(key: key);

  @override
  _MinePreviewDanmuState createState() => _MinePreviewDanmuState();
}

class _MinePreviewDanmuState extends State<MinePreviewDanmu> with SingleTickerProviderStateMixin {

  AnimationController _animationController;
  Animation _animation;
  @override
  void initState() {
    super.initState();

    _animationController = AnimationController(vsync: this, duration: Duration(milliseconds: 5000));
    _animation = Tween(begin: Offset(1,0), end: Offset(-1,0)).animate(_animationController);
    _animationController.forward();
    _animationController.addListener(() { 
      if(_animationController.isCompleted) {
        if(widget.onAnimationFinish != null) widget.onAnimationFinish(widget.key, widget.model.mobile);
      }
    });
  }

  @override
  void dispose() {
    _animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Positioned(
      right: 0,
      left: 0,
      top: widget.offsetTop,
      child: SlideTransition(
        position: _animation,
        child: Container(
          alignment: Alignment.centerRight,
          child: Container(
            decoration: BoxDecoration(
              color: Colors.black26,
              borderRadius: BorderRadius.circular(20)
            ),
            child: Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                Padding(
                  padding: const EdgeInsets.only(left:1, top: 1, bottom: 1),
                  child: CustomCircleAvatar(size: 25.h, url: widget.model.avatar,),
                ),
                Flexible(
                  flex: 1,
                  child: Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 10),
                    child: Text(widget.model.message, maxLines: 1, style: instanceTextStyle(12, Colors.white),),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}